package com.ht.controller;


import cn.hutool.json.JSONUtil;
import com.ht.data.Result;
import com.ht.dto.RehabilitationTask;
import com.ht.dto.User;
import com.ht.service.IRehabilitationTaskService;
import com.ht.util.JwtUtil;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 代齐园
 * @since 2022-05-25
 */
@RestController
@RequestMapping("/rehabilitationTask")
@Api("康复任务")
public class RehabilitationTaskController {
    @Autowired
    private IRehabilitationTaskService rehabilitationTaskService;

    @GetMapping("/RehabilitationTaskStatus/{status}")
    @ApiOperation(value = "查询患者康复任务的完成状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "用户token",required = true,paramType = "header"),
            @ApiImplicitParam(name = "status",value = "完成状态：0/1 未完成/已完成",required = true,paramType = "header")
    })
    public Result RehabilitationTaskStatus(@RequestHeader("Authtoken")String token,@PathVariable("status") String status){
        Claims claims = new JwtUtil().parseJwt(token);
        User user = JSONUtil.toBean(claims.getSubject(), User.class);
        List<RehabilitationTask> rehabilitationTasks = rehabilitationTaskService.RehabilitationTaskStatus(user.getId(),status);
        return Result.OK().setData(rehabilitationTasks);

    }

}
